/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package taglibs;

import daos.CategoryDAO;
import java.util.ArrayList;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import models.Category;
import util.Common;

/**
 *
 * @author trietto
 */
public class Search extends TagSupport {

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    /*
     * (non-Javadoc)
     * @see javax.servlet.jsp.tagext.TagSupport#doStartTag()
     */
    public int doStartTag() {
        try {
            JspWriter writer = pageContext.getOut();

            ArrayList<String> lstCategoriesData = new ArrayList<String>();
            ArrayList<Category> lstCategories = CategoryDAO.singleton().selectAll();
            for (Category category : lstCategories) {
                lstCategoriesData.add(category.getName() + "\t" + category.getCategoryId());
            }
             writer.println("<form action='BookSearch.jsp' method='POST'>");
            writer.println("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
            writer.println("<tr>");
            writer.println("<td colspan=2 align='center'><b>SEARCH BOOK</b><br></td>");
            writer.println("</tr>");
            writer.println("<tr>");
            writer.println("<td>Category:</td>");
            writer.println("<td>" + Common.createComboBox("cbCategory", "cbCategory", (String[]) (lstCategoriesData.toArray(new String[0])), "", "") + "</td>");
            writer.println("</tr>");
            writer.println("<tr>");
            writer.println("<td>Name:</td>");
            writer.println("<td>" + Common.createTextbox("txtName", "txtName", "", "", "") + "</td>");
            writer.println("</tr>");
            writer.println("<tr colspan='2'>");
            writer.println("<td>" + Common.createSubmitButton("btnSearch", "btnSearch", "Search", "") + "</td>");
            writer.println("</tr>");
            writer.println("</table>");
            writer.println("</form>");
        } catch (Exception e) {
        }
        return SKIP_BODY;
    }
}
